package entity

import (
	"strconv"
	"time"

	"shqsoft.cn/pasnj/base"
	"shqsoft.cn/pasnj/bi/cube"
)

//对公存款认定分户情况
type MinOper struct {
	ID        int        `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	TRTD      *time.Time `gorm:"column:TRTD";type:date;`
	OrganName string     `gorm:"column:OrganName"`
	CHTP      string     `gorm:"column:CHTP"` //
	ITNM      string     `gorm:"column:ITNM"`
	CHNM      string     `gorm:"column:CHNM"`
	ACNO      string     `gorm:"column:ACNO"`
	CUNM      string     `gorm:"column:CUNM"`
	TRCT      int        `gorm:"column:TRCT"`
	HDCH      float64    `gorm:"column:HDCH"`
	ACTP      int        `gorm:"column:ACTP"`
	ITNM3     string     `gorm:"column:NTPM3"` //
	ITID      int        `gorm:"column:ITID"`
	NTPN1     int        `gorm:"column:NTPN1"`
	NTPM1     string     `gorm:"column:NTPM1"`
	ACNM      string     `gorm:"column:ACNM"`
	// KHJL1     string     `gorm:"-"`
	// JE1       string     `gorm:"-"`
	// KHJL2     string     `gorm:"-"`
	// JE2       string     `gorm:"-"`
	// KHJL3     string     `gorm:"-"`
	// JE3       string     `gorm:"-"`
	// KHJL4     string     `gorm:"-"`
	// JE4       string     `gorm:"-"`
	// KHJL5     string     `gorm:"-"`
	// JE5       string     `gorm:"-"`
	// KHJL6     string     `gorm:"-"`
	// JE6       string     `gorm:"-"`
	// KHJL7     string     `gorm:"-"`
	// JE7       string     `gorm:"-"`
	YG1 string   `gorm:"-"`
	ZB1 *float64 `gorm:"-"`
	YG2 string   `gorm:"-"`
	ZB2 *float64 `gorm:"-"`
	YG3 string   `gorm:"-"`
	ZB3 *float64 `gorm:"-"`
	YG4 string   `gorm:"-"`
	ZB4 *float64 `gorm:"-"`
	YG5 string   `gorm:"-"`
	ZB5 *float64 `gorm:"-"`
}

//TableName 对公存款认定分户情况
func (MinOper) TableName() string {
	return "V_MIN_OPER"
}

func (c *MinOper) AfterFind() (err error) {
	var share *cube.Share
	share, err = cube.GetShare("comp_acco_oper")
	if err != nil {
		return
	}
	var diviMap map[string]float64
	diviMap, err = share.GetDivision(strconv.Itoa(c.ID))
	if err != nil {
		return
	}
	i := 0
	for k, v := range diviMap {
		val := v
		i++
		switch i {
		case 1:
			c.YG1 = k
			c.ZB1 = &val
		case 2:
			c.YG2 = k
			c.ZB2 = &val
		case 3:
			c.YG3 = k
			c.ZB3 = &val
		case 4:
			c.YG4 = k
			c.ZB4 = &val
		case 5:
			c.YG5 = k
			c.ZB5 = &val
		default:
			break
		}
	}
	return
}

func MinOperEF() base.EntityFunc {
	return func() interface{} {
		entity := MinOper{}
		return &entity
	}
}
func MinOperESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []MinOper
		return &entities
	}
}

func init() {
	dao := base.NewDefaultDao(MinOperEF(), MinOperESF(), nil)
	filter := base.DefaultFilter{
		FilterColName: "ID",
		TableName:     "T_MIN_OPER_DIVI",
		EmidColName:   "EMID",
		AcidColName:   "ACID",
		WhereCause:    "ISWO=0",
	}
	dao.Fileter = &filter
	base.DaoPoolObj.Put("MinOper", dao)
}
